package org.example;

import org.example.observer.Count;
import org.example.observer.DescSort;
import org.example.observer.DistinctSort;
import org.example.observer.Observer;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Editor {
    public static void main(String[] args) {
        /**
         * 测试数据见txt
         */
        List<Observer> list = new ArrayList<>();

        // attach方法
        Collections.addAll(list,new Count(), new DistinctSort(), new DescSort());

        // notify方法
        Scanner scanner = new Scanner(System.in);
        System.out.println("-------文本编辑区--------");
        System.out.println("输入exit退出");
        String word = "";
        while (true){
            word = scanner.next();
            if(word.equals("exit")) break;
            for(Observer ob : list){
                ob.response(word);
            }
        }
        System.out.println("-------文本信息统计区--------");
        list.forEach(Observer::show);
    }
}